/*
 *  Copyright 2011 yura.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */

package org.opu.vcforms.bean.model;

import org.opu.vcforms.bean.Template;
import org.opu.vcforms.view.View;

/**
 *  AvailableGroup value dependece of semestrs, faculties, courses.
 * If it`s value reseted (set new set) - SelectedGroup cleared;
 *
 * @author yura
 */
public class ModelAvailableSource extends MultiViewModel<View>{
    private ComboBoxModel<Template> templates; //      [statements... |▼]

    private ComboBoxModel<Integer> semestrs;   //  semestrs: [1    |▼]
    private ComboBoxModel<Facultie> faculties; // faculties: [FAVT |▼]
    private ComboBoxModel<Integer> courses;    //   courses: [1    |▼]

    private DoubleListModel groups;            //  +---------+       +---------+
                                               //  | AC-073  |  ->   | AC-071  |
                                               //  | AC-072  |  <-   |         |
                                               //  +---------+       +---------+

    /**
     *  Create empty instance
     */
    public ModelAvailableSource() {
        this(new ComboBoxModel<Template>(),
                new ComboBoxModel<Integer>(),
                new ComboBoxModel<Integer>(),
                new ComboBoxModel<Facultie>(),
                new DoubleListModel());
    }

    public ModelAvailableSource(
            ComboBoxModel<Template> templates,
            ComboBoxModel<Integer> courses,
            ComboBoxModel<Integer> semestrs,
            ComboBoxModel<Facultie> faculties,
            DoubleListModel groups) {
        this.templates = templates;
        this.courses = courses;
        this.semestrs = semestrs;
        this.faculties = faculties;
        this.groups = groups;
    }

    public ComboBoxModel<Integer> getCourses() {
        return courses;
    }

    public void setCourses(ComboBoxModel<Integer> courses) {
        this.courses.reset(courses);
    }

    public ComboBoxModel<Facultie> getFaculties() {
        return faculties;
    }

    public void setFaculties(ComboBoxModel<Facultie> faculties) {
        this.faculties.reset(faculties);
    }

    public ComboBoxModel<Integer> getSemestrs() {
        return semestrs;
    }

    public void setSemestrs(ComboBoxModel<Integer> semestrs) {
        this.semestrs.reset(semestrs);
    }

    public ComboBoxModel<Template> getTemplates() {
        return templates;
    }

    public void setTemplates(ComboBoxModel<Template> templates) {
        this.templates.reset(templates);
    }

    public DoubleListModel getGroups() {
        return groups;
    }

    public void setGroups(DoubleListModel groups) {
        this.groups.setAvailableGroup(groups.getAvailableGroup());
        this.groups.setSelectedGroup(groups.getSelectedGroup());
    }

    @Override
    public View[] viewsArray() {
        return views.toArray(new View[viewsCount()]);
    }
}
